package com.system.demo.mapper.dynamicSqlProvider;

import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.jdbc.SQL;

public class LeaveSqlProvider {
    public String selectLeaveByConditions(@Param("uid") String uid,
                                          @Param("userName") String userName,
                                          @Param("startTime") String startTime,
                                          @Param("endTime") String endTime,
                                          @Param("status") Integer status,
                                          @Param("stuClass") String stuClass) {
        return new SQL() {{
            SELECT("*");
            FROM("leave_school");
            // 动态条件
            if (uid != null && !uid.isEmpty()) {
                WHERE("uid = #{uid}");
            }
            if(userName != null && !userName.isEmpty())
            {
                WHERE("user_name = #{userName}");
            }
            if (stuClass != null && !stuClass.isEmpty()) {
                WHERE("LEFT(uid, 2) = #{stuClass}");
            }
            if (status != null) {
                WHERE("status = #{status}");
            }
            if (startTime != null&&startTime.length()>0) {
                WHERE("leaving_time >= #{startTime}");
            }
            if (endTime != null&&endTime.length()>0) {
                WHERE("leaving_time <= #{endTime}");
            }
        }}.toString();
    }
}
